﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Frogism.Domain
{
    public class DrinkManager
    {
        private Core.Drinking.IDrinkRepository Repository
        {
            get
            {
                return new Data._2.DrinkRepository();
            }
        }
        public IEnumerable<Core.Drinking.DrinkType> DrinkTypeList()
        {
            return Repository.DrinkTypeList();
        }


        public Core.Drinking.DrinkDay DrinksForDay(DateTime runDate)
        {
            var daylist = Repository.DrinksForDay(runDate);
            Core.Drinking.DrinkDay day;
            if (daylist == null || daylist.Count == 0)
            {
                day = new Core.Drinking.DrinkDay() { Day = runDate, Items = new System.Collections.ObjectModel.Collection<Core.Drinking.DrinkItem>() };
            }
            else
            {
                day = daylist[0];
            }
            var allitems = DrinkTypeList();
            foreach (var item in allitems)
            {
                if (day.Items.FirstOrDefault(a => a.DrinkType.Equals(item))==null)
                {
                    day.Items.Add(new Core.Drinking.DrinkItem() { Count = 0, IsConfirmed = false, DrinkType = item });
                }
            }
            return day;

        }
    }
}
